<!DOCTYPE html>
<!-- saved from url=(0055)https://www.cnblogs.com/liuqing576598117/p/9936400.html -->
<html lang="zh-cn"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="referrer" content="origin-when-crossorigin">
    <meta name="description" content="前台 VUE 界面： 后台java代码:（rest接口，供前台进行调用） 注意：上面的方法有一个小问题：用过url去网络获取 inputStream 是一点一点不断获取，获取的过程中就去写这个 inp">
    <meta property="og:description" content="前台 VUE 界面： 后台java代码:（rest接口，供前台进行调用） 注意：上面的方法有一个小问题：用过url去网络获取 inputStream 是一点一点不断获取，获取的过程中就去写这个 inp">
    <meta http-equiv="Cache-Control" content="no-transform">
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>前后台交互实现点击超链接通过指定的 url 去网络或者文件服务器下载文件 - 一中晴哥威武 - 博客园</title>
    <link id="favicon" rel="shortcut icon" href="https://common.cnblogs.com/favicon.svg" type="image/svg+xml">
    
    <style>:not(.cnblogs_code):not(.cnblogs_Highlighter)>pre:not([class*="language-"]):not([highlighted]):not(.hljs) {
        background: rgb(245, 245, 245);
        padding: 5px;
        border: 1px solid rgb(204, 204, 204);
        border-radius: 3px;
        border-color: transparent;
        color: rgb(0, 0, 0);
        font-family: "Courier New", sans-serif;
    }:not(.cnblogs_code):not(.cnblogs_Highlighter)>pre:not([highlighted]) code:not(.hljs) {
            background: rgb(245, 245, 245) !important;
            border-color: transparent !important;
        }</style><link rel="stylesheet" href="./test_files/blog-common.min.css">
    <link id="MainCss" rel="stylesheet" href="./test_files/bundle-arrow.min.css">
    <link id="highlighter-theme-cnblogs" type="text/css" rel="stylesheet" href="./test_files/cnblogs.css">
    
    <link id="mobile-style" media="only screen and (max-width: 767px)" type="text/css" rel="stylesheet" href="./test_files/bundle-arrow-mobile.min.css">
    
    <link type="application/rss+xml" rel="alternate" href="https://www.cnblogs.com/liuqing576598117/rss">
    <link type="application/rsd+xml" rel="EditURI" href="https://www.cnblogs.com/liuqing576598117/rsd.xml">
    <link type="application/wlwmanifest+xml" rel="wlwmanifest" href="https://www.cnblogs.com/liuqing576598117/wlwmanifest.xml">
    <script type="text/javascript" async="" src="./test_files/analytics.js.下载"></script><script type="text/javascript" src="./test_files/encoder.js.下载"></script><script>
        var currentBlogId = 447335;
        var currentBlogApp = 'liuqing576598117';
        var cb_enable_mathjax = false;
        var isLogined = false;
        var isBlogOwner = false;
        var skinName = 'arrow';
        var visitorUserId = '';
        var hasCustomScript = false;
        try {
            if (hasCustomScript && document.referrer && document.referrer.indexOf('baidu.com') >= 0) {
                Object.defineProperty(document, 'referrer', { value: '' });
                Object.defineProperty(Document.prototype, 'referrer', { get: function(){ return ''; } });
            }
        } catch(error) { }
        window.codeHighlightEngine = 1;
        window.enableCodeLineNumber = false;
        window.codeHighlightTheme = 'cnblogs';
    </script>
        <script>
            var currentPostDateAdded = '2018-11-09 17:45';
        </script>
    <script src="./test_files/jquery-2.2.0.min.js.下载"></script>
    <script src="./test_files/blog-common.min.js.下载"></script><style type="text/css">.medium-zoom-overlay{position:fixed;top:0;right:0;bottom:0;left:0;opacity:0;transition:opacity .3s;will-change:opacity}.medium-zoom--opened .medium-zoom-overlay{cursor:pointer;cursor:zoom-out;opacity:1}.medium-zoom-image{cursor:pointer;cursor:zoom-in;transition:transform .3s cubic-bezier(.2,0,.2,1)!important}.medium-zoom-image--hidden{visibility:hidden}.medium-zoom-image--opened{position:relative;cursor:pointer;cursor:zoom-out;will-change:transform}</style><script id="hljs-script" async="" data-loaded="true" src="./test_files/highlight.min.js.下载"></script>
    
    
    
<meta http-equiv="origin-trial" content="AxujKG9INjsZ8/gUq8+dTruNvk7RjZQ1oFhhgQbcTJKDnZfbzSTE81wvC2Hzaf3TW4avA76LTZEMdiedF1vIbA4AAABueyJvcmlnaW4iOiJodHRwczovL2ltYXNkay5nb29nbGVhcGlzLmNvbTo0NDMiLCJmZWF0dXJlIjoiVHJ1c3RUb2tlbnMiLCJleHBpcnkiOjE2NTI3NzQ0MDAsImlzVGhpcmRQYXJ0eSI6dHJ1ZX0="><meta http-equiv="origin-trial" content="Azuce85ORtSnWe1MZDTv68qpaW3iHyfL9YbLRy0cwcCZwVnePnOmkUJlG8HGikmOwhZU22dElCcfrfX2HhrBPAkAAAB7eyJvcmlnaW4iOiJodHRwczovL2RvdWJsZWNsaWNrLm5ldDo0NDMiLCJmZWF0dXJlIjoiVHJ1c3RUb2tlbnMiLCJleHBpcnkiOjE2NTI3NzQ0MDAsImlzU3ViZG9tYWluIjp0cnVlLCJpc1RoaXJkUGFydHkiOnRydWV9"><meta http-equiv="origin-trial" content="A16nvcdeoOAqrJcmjLRpl1I6f3McDD8EfofAYTt/P/H4/AWwB99nxiPp6kA0fXoiZav908Z8etuL16laFPUdfQsAAACBeyJvcmlnaW4iOiJodHRwczovL2dvb2dsZXRhZ3NlcnZpY2VzLmNvbTo0NDMiLCJmZWF0dXJlIjoiVHJ1c3RUb2tlbnMiLCJleHBpcnkiOjE2NTI3NzQ0MDAsImlzU3ViZG9tYWluIjp0cnVlLCJpc1RoaXJkUGFydHkiOnRydWV9"><meta http-equiv="origin-trial" content="AxBHdr0J44vFBQtZUqX9sjiqf5yWZ/OcHRcRMN3H9TH+t90V/j3ENW6C8+igBZFXMJ7G3Pr8Dd13632aLng42wgAAACBeyJvcmlnaW4iOiJodHRwczovL2dvb2dsZXN5bmRpY2F0aW9uLmNvbTo0NDMiLCJmZWF0dXJlIjoiVHJ1c3RUb2tlbnMiLCJleHBpcnkiOjE2NTI3NzQ0MDAsImlzU3ViZG9tYWluIjp0cnVlLCJpc1RoaXJkUGFydHkiOnRydWV9"><meta http-equiv="origin-trial" content="A88BWHFjcawUfKU3lIejLoryXoyjooBXLgWmGh+hNcqMK44cugvsI5YZbNarYvi3roc1fYbHA1AVbhAtuHZflgEAAAB2eyJvcmlnaW4iOiJodHRwczovL2dvb2dsZS5jb206NDQzIiwiZmVhdHVyZSI6IlRydXN0VG9rZW5zIiwiZXhwaXJ5IjoxNjUyNzc0NDAwLCJpc1N1YmRvbWFpbiI6dHJ1ZSwiaXNUaGlyZFBhcnR5Ijp0cnVlfQ=="><meta http-equiv="origin-trial" content="A8FHS1NmdCwGqD9DwOicnHHY+y27kdWfxKa0YHSGDfv0CSpDKRHTQdQmZVPDUdaFWUsxdgVxlwAd6o+dhJykPA0AAACWeyJvcmlnaW4iOiJodHRwczovL2RvdWJsZWNsaWNrLm5ldDo0NDMiLCJmZWF0dXJlIjoiQ29udmVyc2lvbk1lYXN1cmVtZW50IiwiZXhwaXJ5IjoxNjQzMTU1MTk5LCJpc1N1YmRvbWFpbiI6dHJ1ZSwiaXNUaGlyZFBhcnR5Ijp0cnVlLCJ1c2FnZSI6InN1YnNldCJ9"><meta http-equiv="origin-trial" content="A8zdXi6dr1hwXEUjQrYiyYQGlU3557y5QWDnN0Lwgj9ePt66XMEvNkVWOEOWPd7TP9sBQ25X0Q15Lr1Nn4oGFQkAAACceyJvcmlnaW4iOiJodHRwczovL2dvb2dsZXN5bmRpY2F0aW9uLmNvbTo0NDMiLCJmZWF0dXJlIjoiQ29udmVyc2lvbk1lYXN1cmVtZW50IiwiZXhwaXJ5IjoxNjQzMTU1MTk5LCJpc1N1YmRvbWFpbiI6dHJ1ZSwiaXNUaGlyZFBhcnR5Ijp0cnVlLCJ1c2FnZSI6InN1YnNldCJ9"><meta http-equiv="origin-trial" content="A4/Htern2udN9w3yJK9QgWQxQFruxOXsXL7cW60DyCl0EZFGCSme/J33Q/WzF7bBkVvhEWDlcBiUyZaim5CpFQwAAACceyJvcmlnaW4iOiJodHRwczovL2dvb2dsZXRhZ3NlcnZpY2VzLmNvbTo0NDMiLCJmZWF0dXJlIjoiQ29udmVyc2lvbk1lYXN1cmVtZW50IiwiZXhwaXJ5IjoxNjQzMTU1MTk5LCJpc1N1YmRvbWFpbiI6dHJ1ZSwiaXNUaGlyZFBhcnR5Ijp0cnVlLCJ1c2FnZSI6InN1YnNldCJ9"><script src="./test_files/pubads_impl_2021113001.js.下载" async=""></script></head>
<body class="skin-arrow has-navbar has-bannerbar">
    <a name="top"></a>
        <a href="https://c.gridsumdissector.com/r/?gid=gad_545_t8eyuf99&amp;ck=1057&amp;adk=10671&amp;autorefresh=__AUTOREFRESH__" target="_blank" rel="nofollow" onclick="countClicks(&#39;ad&#39;, &#39;C0-火山引擎&#39;)">
            <div class="bannerbar forpc" style="display: flex; background-color: #11225a;">
                <img src="./test_files/volcengine-b0c0-1.jpg" onload="impressC0(&#39;火山引擎&#39;, &#39;https://i.gridsumdissector.com/v/?gscmd=impress&amp;gid=gad_545_t8eyuf99&amp;ck=1057&amp;adk=10671&amp;autorefresh=__AUTOREFRESH__&amp;ts=__TS__&#39;)" alt="">
                <img src="./test_files/volcengine-b0c0-2.jpg" alt="">
                <img style="margin-left: auto;" src="./test_files/volcengine-b0c0-3.jpg" alt="">
            </div>
        </a>
            <div id="bannerbar" class="bannerbar-mobile formobile">
                <a href="https://c.gridsumdissector.com/r/?gid=gad_545_51wu7ojr&amp;ck=1057&amp;adk=10674&amp;autorefresh=__AUTOREFRESH__" onclick="countClicks(&#39;ad&#39;, &#39;M2-火山引擎&#39;)" rel="nofollow">
                    <img src="./test_files/volcengine-m2.jpg" alt="" onload="impressM2(&#39;火山引擎&#39;, &#39;https://i.gridsumdissector.com/v/?gscmd=impress&amp;gid=gad_545_51wu7ojr&amp;ck=1057&amp;adk=10674&amp;autorefresh=__AUTOREFRESH__&amp;ts=__TS__&#39;)">
                </a>
            </div>
    <div id="top_nav" class="navbar forpc">
        <nav id="nav_main" class="navbar-main">
            <ul id="nav_left" class="navbar-list navbar-left">
                <li class="navbar-branding"><a href="https://www.cnblogs.com/" title="开发者的网上家园"><img src="./test_files/logo.svg" alt="博客园Logo"></a></li>
                <li><a href="https://www.cnblogs.com/" onclick="countClicks(&#39;skin-navbar-sitehome&#39;)">首页</a></li>
                <li><a href="https://news.cnblogs.com/" onclick="countClicks(&#39;nav&#39;, &#39;skin-navbar-news&#39;)">新闻</a></li>
                <li><a href="https://q.cnblogs.com/" onclick="countClicks(&#39;nav&#39;, &#39;skin-navbar-q&#39;)">博问</a></li>
                <li><a id="nav_brandzone" href="https://brands.cnblogs.com/" onclick="countClicks(&#39;nav&#39;, &#39;skin-navbar-brands&#39;)">专区</a></li>
                <li><a href="https://ing.cnblogs.com/" onclick="countClicks(&#39;nav&#39;, &#39;skin-navbar-ing&#39;)">闪存</a></li>
                <li><a href="https://edu.cnblogs.com/" onclick="countClicks(&#39;nav&#39;, &#39;skin-navbar-edu&#39;)">班级</a></li>
            </ul>
            <ul id="nav_right" class="navbar-list navbar-right">
                <li>
                    <form id="zzk_search" class="navbar-search" action="https://zzk.cnblogs.com/s" method="get">
                        <input name="w" id="zzk_search_input" placeholder="代码改变世界" type="text" tabindex="3">
                        <button type="submit" id="zzk_search_button">
                            <img src="./test_files/search.svg" alt="搜索">
                        </button>
                    </form>
                </li>
                <li id="navbar_login_status" class="navbar-list">
                    <a class="navbar-user-info navbar-blog" href="https://i.cnblogs.com/EditPosts.aspx?opt=1" alt="写随笔" title="写随笔" style="display: none;">
                        <img id="new_post_icon" class="navbar-icon" src="./test_files/newpost.svg" alt="写随笔">
                    </a>
                    <a id="navblog-myblog-icon" class="navbar-user-info navbar-blog" href="https://passport.cnblogs.com/GetBlogApplyStatus.aspx" alt="我的博客" title="我的博客" style="display: none;">
                        <img id="myblog_icon" class="navbar-icon" src="./test_files/myblog.svg" alt="我的博客">
                    </a>
                    <a class="navbar-user-info navbar-message navbar-icon-wrapper" href="https://msg.cnblogs.com/" alt="短消息" title="短消息" style="display: none;">
                        <img id="msg_icon" class="navbar-icon" src="./test_files/message.svg" alt="短消息">
                        <span id="msg_count" style="display: none"></span>
                    </a>
                    <div id="user_info" class="navbar-user-info dropdown" style="display: none;">
                        <a class="dropdown-button" href="https://home.cnblogs.com/">
                            <img id="user_icon" class="navbar-avatar" src="./test_files/avatar-default.svg" alt="用户头像">
                        </a>
                        <div class="dropdown-menu">
                            <a id="navblog-myblog-text" href="https://passport.cnblogs.com/GetBlogApplyStatus.aspx">我的博客</a>
                            <a href="https://home.cnblogs.com/">我的园子</a>
                            <a href="https://account.cnblogs.com/settings/account">账号设置</a>
                            <a href="javascript:void(0)" id="navbar_lite_mode_toggle" title="简洁模式会使用简洁款皮肤显示所有博客">
    简洁模式 <img id="navbar_lite_mode_on" src="./test_files/lite-mode-check.svg" class="hide"><span id="navbar_lite_mode_spinner" class="hide">...</span>
</a>
                            <a href="javascript:void(0)" onclick="account.logout();">退出登录</a>
                        </div>
                    </div>
                    <a class="navbar-anonymous" href="https://account.cnblogs.com/signup/" style="display: inline;">注册</a>
                    <a class="navbar-anonymous" href="javascript:void(0);" onclick="account.login()" style="display: inline;">登录</a>
                </li>
            </ul>
        </nav>
    </div>

    
    <!--done-->
<div id="header">
	
<!--done-->
<div class="header">
	<div class="headerText">
		<a id="Header1_HeaderTitle" class="headermaintitle HeaderMainTitle" href="https://www.cnblogs.com/liuqing576598117/">一中晴哥威武</a>
<br>
		
	</div>
</div>


</div>
<div id="mylinks">
<!--done-->
<a id="blog_nav_sitehome" class="menu" href="https://www.cnblogs.com/">
博客园</a>
&nbsp;&nbsp;&nbsp;

<a id="blog_nav_myhome" class="menu" href="https://www.cnblogs.com/liuqing576598117/">
首页</a>
&nbsp;&nbsp;&nbsp;


<a id="blog_nav_newpost" class="menu" href="https://i.cnblogs.com/EditPosts.aspx?opt=1">
新随笔</a>
&nbsp;&nbsp;&nbsp;

<a id="blog_nav_contact" class="menu" href="https://msg.cnblogs.com/send/%E4%B8%80%E4%B8%AD%E6%99%B4%E5%93%A5%E5%A8%81%E6%AD%A6">
联系</a>&nbsp;&nbsp;&nbsp;

<a id="blog_nav_rss" class="menu" href="javascript:void(0)" data-rss="https://www.cnblogs.com/liuqing576598117/rss/">
订阅</a>
<a id="blog_nav_rss_image" href="https://www.cnblogs.com/liuqing576598117/rss/">
    <img src="./test_files/xml.gif" alt="订阅">
</a>&nbsp;&nbsp;&nbsp;

<a id="blog_nav_admin" class="menu" href="https://i.cnblogs.com/">
管理</a>


</div>
<div id="mytopmenu">
	
		<div class="blogStats">随笔 - 157&nbsp;
文章 - 0&nbsp;评论 - 4&nbsp;阅读 - 
<span title="总阅读数: 149257">
14万</span>
</div>


	
</div>
<div id="leftcontent">
	
		<div id="leftcontentcontainer">
			<div id="blog-calendar" style="">

<table id="blogCalendar" class="Cal" cellspacing="0" cellpadding="0" title="Calendar" border="0">
    <tbody>
        <tr>
            <td colspan="7">
                <table class="CalTitle" cellspacing="0" border="0">
                    <tbody>
                        <tr>
                            <td class="CalNextPrev">
                                <a href="javascript:void(0);" onclick="loadBlogCalendar(&#39;2021/11/03&#39;); return false;">&lt;</a>
                            </td>
                            <td align="center">2021年12月</td>
                            <td align="right" class="CalNextPrev">
                                <a href="javascript:void(0);" onclick="loadBlogCalendar(&#39;2022/01/03&#39;); return false;">&gt;</a>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>
    <tr>
        <th class="CalDayHeader" align="center" abbr="日" scope="col">日</th>
        <th class="CalDayHeader" align="center" abbr="一" scope="col">一</th>
        <th class="CalDayHeader" align="center" abbr="二" scope="col">二</th>
        <th class="CalDayHeader" align="center" abbr="三" scope="col">三</th>
        <th class="CalDayHeader" align="center" abbr="四" scope="col">四</th>
        <th class="CalDayHeader" align="center" abbr="五" scope="col">五</th>
        <th class="CalDayHeader" align="center" abbr="六" scope="col">六</th>
    </tr>
            <tr>
                            <td class="CalOtherMonthDay" align="center">28</td>
                            <td class="CalOtherMonthDay" align="center">29</td>
                            <td class="CalOtherMonthDay" align="center">30</td>
                        <td class="" align="center">
                            1
                        </td>
                        <td class="" align="center">
                            2
                        </td>
                        <td class="CalTodayDay" align="center">
                            3
                        </td>
                    <td class="CalWeekendDay" align="center">
                        4
                    </td>
            </tr>
                <tr>
                        <td class="CalWeekendDay" align="center">
                            5
                        </td>
                            <td class="" align="center">
                                6
                            </td>
                            <td class="" align="center">
                                7
                            </td>
                            <td class="" align="center">
                                8
                            </td>
                            <td class="" align="center">
                                9
                            </td>
                            <td class="" align="center">
                                10
                            </td>
                        <td class="CalWeekendDay" align="center">
                            11
                        </td>
                </tr>
                <tr>
                        <td class="CalWeekendDay" align="center">
                            12
                        </td>
                            <td class="" align="center">
                                13
                            </td>
                            <td class="" align="center">
                                14
                            </td>
                            <td class="" align="center">
                                15
                            </td>
                            <td class="" align="center">
                                16
                            </td>
                            <td class="" align="center">
                                17
                            </td>
                        <td class="CalWeekendDay" align="center">
                            18
                        </td>
                </tr>
                <tr>
                        <td class="CalWeekendDay" align="center">
                            19
                        </td>
                            <td class="" align="center">
                                20
                            </td>
                            <td class="" align="center">
                                21
                            </td>
                            <td class="" align="center">
                                22
                            </td>
                            <td class="" align="center">
                                23
                            </td>
                            <td class="" align="center">
                                24
                            </td>
                        <td class="CalWeekendDay" align="center">
                            25
                        </td>
                </tr>
                <tr>
                        <td class="CalWeekendDay" align="center">
                            26
                        </td>
                            <td class="" align="center">
                                27
                            </td>
                            <td class="" align="center">
                                28
                            </td>
                            <td class="" align="center">
                                29
                            </td>
                            <td class="" align="center">
                                30
                            </td>
                            <td class="" align="center">
                                31
                            </td>
                        <td class="CalOtherMonthDay" align="center">
                            1
                        </td>
                </tr>
                <tr>
                        <td class="CalOtherMonthDay" align="center">
                            2
                        </td>
                            <td class="CalOtherMonthDay" align="center">
                                3
                            </td>
                            <td class="CalOtherMonthDay" align="center">
                                4
                            </td>
                            <td class="CalOtherMonthDay" align="center">
                                5
                            </td>
                            <td class="CalOtherMonthDay" align="center">
                                6
                            </td>
                            <td class="CalOtherMonthDay" align="center">
                                7
                            </td>
                        <td class="CalOtherMonthDay" align="center">
                            8
                        </td>
                </tr>
    </tbody>
</table></div><script>loadBlogDefaultCalendar();</script><br>
			<div id="sidebar_news" class="newsItem"><!--done-->
<div class="newsItem">
	
<div id="blog-news">
    
    <div id="profile_block">
        昵称：
        <a href="https://home.cnblogs.com/u/liuqing576598117/">
            一中晴哥威武
        </a>
        <br>
        园龄：
        <a href="https://home.cnblogs.com/u/liuqing576598117/" title="入园时间：2018-07-26">
            3年4个月
        </a>
        <br>
        粉丝：
        <a href="https://home.cnblogs.com/u/liuqing576598117/followers/">
            7
        </a>
        <br>
        关注：
        <a href="https://home.cnblogs.com/u/liuqing576598117/followees/">
            0
        </a>
        <div id="p_b_follow">
<a href="javascript:void(0)" onclick="follow(&#39;3891dd62-af14-49eb-38a3-08d5f07434ca&#39;)">+加关注</a></div>
        <script>getFollowStatus('3891dd62-af14-49eb-38a3-08d5f07434ca');</script>
    </div>
</div>
</div>

</div>
<div id="sidebar_c3"></div>
			<div id="blog-sidecolumn"><!-- 搜索 -->
<div id="sidebar_search" class="sidebar-block">
    <div id="sidebar_search" class="mySearch">
        <h3 class="catListTitle">搜索</h3>
        <div id="sidebar_search_box">
            <div id="widget_my_zzk" class="div_my_zzk">
                <input type="text" id="q" onkeydown="return zzk_go_enter(event);" class="input_my_zzk">&nbsp;<input onclick="zzk_go()" type="button" value="找找看" id="btnZzk" class="btn_my_zzk">
            </div>
            <div id="widget_my_google" class="div_my_zzk">
                <input type="text" name="google_q" id="google_q" onkeydown="return google_go_enter(event);" class="input_my_zzk">&nbsp;<input onclick="google_go()" type="button" value="谷歌搜索" class="btn_my_zzk">
            </div>
        </div>
    </div>
</div>

<!-- 常用链接 -->
<div id="sidebar_shortcut" class="sidebar-block">
<h3 class="catListTitle">
常用链接
</h3>
<ul>
    
<li><a href="https://www.cnblogs.com/liuqing576598117/p/" title="我的博客的随笔列表">我的随笔</a></li>
<li><a href="https://www.cnblogs.com/liuqing576598117/MyComments.html" title="我的发表过的评论列表">我的评论</a></li>
<li><a href="https://www.cnblogs.com/liuqing576598117/OtherPosts.html" title="我评论过的随笔列表">我的参与</a></li>
<li><a href="https://www.cnblogs.com/liuqing576598117/RecentComments.html" title="我的博客的评论列表">最新评论</a></li>
<li><a href="https://www.cnblogs.com/liuqing576598117/tag/" title="我的博客的标签列表">我的标签</a></li>

</ul>
</div>

<!-- 最新随笔 -->


<!-- 我的标签 -->
<div id="sidebar_toptags" class="sidebar-block"></div>

<!-- 积分与排名 -->


<!-- 随笔分类、随笔档案、文章分类、新闻分类、相册、链接 -->
<div id="sidebar_categories">

    <h1 class="catListTitle">
        
随笔分类



    </h1>
    <ul class="catList">
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1390451.html" class="category-item-link" rel="" target="">Activiti工作流(11)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1390456.html" class="category-item-link" rel="" target="">Github(1)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1390454.html" class="category-item-link" rel="" target="">IDEA工具用法(6)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1390417.html" class="category-item-link" rel="" target="">JVM(7)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1390437.html" class="category-item-link" rel="" target="">Mybatis(4)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1424298.html" class="category-item-link" rel="" target="">Spring(8)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1546620.html" class="category-item-link" rel="" target="">SpringCloud(3)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1390436.html" class="category-item-link" rel="" target="">SpringMVC(3)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1390443.html" class="category-item-link" rel="" target="">Tomcat(2)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1390447.html" class="category-item-link" rel="" target="">VUE(4)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1390477.html" class="category-item-link" rel="" target="">分布式(3)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1390425.html" class="category-item-link" rel="" target="">缓存(4)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1390444.html" class="category-item-link" rel="" target="">集合(7)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1390489.html" class="category-item-link" rel="" target="">其他(56)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1428191.html" class="category-item-link" rel="" target="">设计模式(1)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="false" style="display: none">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1390445.html" class="category-item-link" rel="" target="">数据库(9)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="false" style="display: none">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1678443.html" class="category-item-link" rel="" target="">算法(2)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="false" style="display: none">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1390422.html" class="category-item-link" rel="" target="">锁(7)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="false" style="display: none">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1390441.html" class="category-item-link" rel="" target="">网络协议(7)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="false" style="display: none">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1390418.html" class="category-item-link" rel="" target="">线程(10)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="false" style="display: none">
                
<a href="https://www.cnblogs.com/liuqing576598117/category/1546421.html" class="category-item-link" rel="" target="">消息(1)</a>

            </li>
        <li class="catListItem"><a href="javascript:void(0)" onclick="sideColumnManager.loadMore(this)">更多</a></li>
    </ul>
    <h1 class="catListTitle">
        
随笔档案



    </h1>
    <ul class="catList">
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/archive/2020/08.html" class="category-item-link" rel="" target="">2020年8月(1)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/archive/2020/03.html" class="category-item-link" rel="" target="">2020年3月(8)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/archive/2019/10.html" class="category-item-link" rel="" target="">2019年10月(2)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/archive/2019/09.html" class="category-item-link" rel="" target="">2019年9月(4)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/archive/2019/08.html" class="category-item-link" rel="" target="">2019年8月(2)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/archive/2019/07.html" class="category-item-link" rel="" target="">2019年7月(16)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/archive/2019/06.html" class="category-item-link" rel="" target="">2019年6月(1)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/archive/2019/05.html" class="category-item-link" rel="" target="">2019年5月(2)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/archive/2019/04.html" class="category-item-link" rel="" target="">2019年4月(2)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/archive/2019/03.html" class="category-item-link" rel="" target="">2019年3月(43)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/archive/2019/02.html" class="category-item-link" rel="" target="">2019年2月(6)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/archive/2019/01.html" class="category-item-link" rel="" target="">2019年1月(22)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/archive/2018/12.html" class="category-item-link" rel="" target="">2018年12月(1)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/archive/2018/11.html" class="category-item-link" rel="" target="">2018年11月(6)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="true" style="display: block">
                
<a href="https://www.cnblogs.com/liuqing576598117/archive/2018/10.html" class="category-item-link" rel="" target="">2018年10月(18)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="false" style="display: none">
                
<a href="https://www.cnblogs.com/liuqing576598117/archive/2018/09.html" class="category-item-link" rel="" target="">2018年9月(8)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="false" style="display: none">
                
<a href="https://www.cnblogs.com/liuqing576598117/archive/2018/08.html" class="category-item-link" rel="" target="">2018年8月(11)</a>

            </li>
            <li class="catListItem" data-category-list-item-visible="false" style="display: none">
                
<a href="https://www.cnblogs.com/liuqing576598117/archive/2018/07.html" class="category-item-link" rel="" target="">2018年7月(4)</a>

            </li>
        <li class="catListItem"><a href="javascript:void(0)" onclick="sideColumnManager.loadMore(this)">更多</a></li>
    </ul>
</div>

<!-- 最新评论 -->
<!-- 阅读排行榜 -->
<div id="sidebar_topviewedposts" class="sidebar-block">
<div id="topview_posts_wrap">
    <h3 class="catListTitle">阅读排行榜</h3>
    <div id="TopViewPostsBlock">
        <ul style="word-break:break-all">
                    <li>
                        <a href="https://www.cnblogs.com/liuqing576598117/p/11227007.html">
                            1. Spring循环依赖的三种方式以及解决办法(16906)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/liuqing576598117/p/11451474.html">
                            2. SpringBoot项目的限流(9314)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/liuqing576598117/p/10277053.html">
                            3. JVM老年代和新生代的比例(7230)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/liuqing576598117/p/9606101.html">
                            4. idea中创建多module的maven工程(6232)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/liuqing576598117/p/10334874.html">
                            5. 解决idea启动项目报错:Unable to open debugger port(127.0.0.1:60157):java.net.SocketException"socket closed(5918)
                        </a>
                    </li>
        </ul>
    </div>
</div></div>

<!-- 评论排行榜 -->
<div id="sidebar_topcommentedposts" class="sidebar-block"><div id="topfeedback_posts_wrap">
    <h3 class="catListTitle">评论排行榜</h3>
    <div id="TopFeedbackPostsBlock">
        <ul style="word-break:break-all">
                    <li>
                        <a href="https://www.cnblogs.com/liuqing576598117/p/11227007.html">
                            1. Spring循环依赖的三种方式以及解决办法(1)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/liuqing576598117/p/10303708.html">
                            2. VUE 前端项目优化方法(1)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/liuqing576598117/p/9815031.html">
                            3. Activiti服务类-9 TaskService服务类(1)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/liuqing576598117/p/9606101.html">
                            4. idea中创建多module的maven工程(1)
                        </a>
                    </li>
        </ul>
    </div>
</div></div>

<!-- 推荐排行榜 -->
<div id="sidebar_topdiggedposts" class="sidebar-block">
<div id="topdigg_posts_wrap">
    <div class="catListView">
        <h3 class="catListTitle">推荐排行榜</h3>
        <div id="TopDiggPostsBlock">
            <ul style="word-break: break-all">
                        <li>
                            <a href="https://www.cnblogs.com/liuqing576598117/p/11227007.html">
                                1. Spring循环依赖的三种方式以及解决办法(3)
                            </a>
                        </li>
                        <li>
                            <a href="https://www.cnblogs.com/liuqing576598117/p/12553720.html">
                                2. MySQL常见的七种锁(1)
                            </a>
                        </li>
                        <li>
                            <a href="https://www.cnblogs.com/liuqing576598117/p/12553401.html">
                                3. Java进程故障排查思路及步骤(1)
                            </a>
                        </li>
                        <li>
                            <a href="https://www.cnblogs.com/liuqing576598117/p/11451474.html">
                                4. SpringBoot项目的限流(1)
                            </a>
                        </li>
                        <li>
                            <a href="https://www.cnblogs.com/liuqing576598117/p/11424997.html">
                                5. http GET 和 POST 请求的优缺点和误区(1)
                            </a>
                        </li>
            </ul>
        </div>
    </div>
</div></div><div id="sidebar_recentcomments" class="sidebar-block"><div id="recent_comments_wrap" class="RecentComment">
    <h3 class="catListTitle">最新评论</h3>
    <div class="RecentCommentBlock">
        <ul>
                    <li class="recent_comment_title"><a href="https://www.cnblogs.com/liuqing576598117/p/9815031.html">1. Re:Activiti服务类-9 TaskService服务类</a></li>
                    <li class="recent_comment_body"><p>写的很好，我正好在学习flowable相关，api整理的很详细谢谢。</p>
</li>
                    <li class="recent_comment_author">--泰坦无人声</li>
                    <li class="recent_comment_title"><a href="https://www.cnblogs.com/liuqing576598117/p/9606101.html">2. Re:idea中创建多module的maven工程</a></li>
                    <li class="recent_comment_body">你好，我按照你的文章第一次操作，但是运行时候提示：Failed to execute goal on project Testservice: Could not resolve dependenci...</li>
                    <li class="recent_comment_author">--怪才博士</li>
                    <li class="recent_comment_title"><a href="https://www.cnblogs.com/liuqing576598117/p/11227007.html">3. Re:Spring循环依赖的三种方式以及解决办法</a></li>
                    <li class="recent_comment_body"><p>不行，我的就是@Autowired注解引起的 循环依赖</p>
</li>
                    <li class="recent_comment_author">--lichao1990</li>
                    <li class="recent_comment_title"><a href="https://www.cnblogs.com/liuqing576598117/p/10303708.html">4. Re:VUE 前端项目优化方法</a></li>
                    <li class="recent_comment_body"><p>沙发</p>
</li>
                    <li class="recent_comment_author">--飞翔的蜗牛~</li>
        </ul>
    </div>
</div></div>


</div>
                    <script>loadBlogSideColumn();</script></div>		
	
</div>
<div id="centercontent">
	<!--done-->
<div id="post_detail">
    <div class="post">
        <div class="postTitle">
            <h1>
<a id="cb_post_title_url" class="postTitle2 vertical-middle" href="https://www.cnblogs.com/liuqing576598117/p/9936400.html">
    <span>前后台交互实现点击超链接通过指定的 url 去网络或者文件服务器下载文件</span>
    



</a>
</h1>
        </div>
        <div id="cnblogs_post_body" class="blogpost-body blogpost-body-html">
<p>前台 VUE 界面：</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">el-table-column </span><span style="color: rgba(255, 0, 0, 1)">prop</span><span style="color: rgba(0, 0, 255, 1)">="attachment" </span><span style="color: rgba(255, 0, 0, 1)">align</span><span style="color: rgba(0, 0, 255, 1)">="center" </span><span style="color: rgba(255, 0, 0, 1)">label</span><span style="color: rgba(0, 0, 255, 1)">="附件详情"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
    <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">template </span><span style="color: rgba(255, 0, 0, 1)">slot-scope</span><span style="color: rgba(0, 0, 255, 1)">="scope"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
        <span style="color: rgba(0, 128, 0, 1)">&lt;!--</span><span style="color: rgba(0, 128, 0, 1)">&lt;el-button @click="downloadFile(scope.row.fileName,scope.row.fileUrl)"&gt;{{scope.row.fileName}}&lt;/el-button&gt;</span><span style="color: rgba(0, 128, 0, 1)">--&gt;</span>
        <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">a </span><span style="color: rgba(255, 0, 0, 1)">@click</span><span style="color: rgba(0, 0, 255, 1)">="downloadFile(scope.row.fileName,scope.row.fileUrl)"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>{{scope.row.fileName}}<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">a</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
    <span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">template</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">el-table-column</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<div class="cnblogs_code"><div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy"><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="./test_files/copycode.gif" alt="复制代码"></a></span></div>
<pre><span style="color: rgba(0, 0, 0, 1)">//window.open打开一个新的浏览器窗口，通过 url 对后台的 rest 接口进行调用<br>downloadFile(fileName,fileUrl){
   let param </span>= {"fileUrl": fileUrl, "fileName"<span style="color: rgba(0, 0, 0, 1)">: fileName};
　　window.open(
   　　downloadManage.downloadFile(param),
      　　</span><span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.openType
      );
},</span></pre>
<div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy"><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="./test_files/copycode.gif" alt="复制代码"></a></span></div></div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)"> 下载文件，对参数 url 和 fileName 进行拼接处理，然后通过 window.open 对后台的 rest 接口进行调用 </span><span style="color: rgba(0, 128, 0, 1)">*/</span><span style="color: rgba(0, 0, 0, 1)">
export const downloadManage </span>=<span style="color: rgba(0, 0, 0, 1)"> {
  downloadFile: (query) </span>=&gt; requestGetUrl('/process/downloadFile.do_', query, 'post'<span style="color: rgba(0, 0, 0, 1)">),
};</span></pre>
</div>
<p>&nbsp;</p>
<p>后台java代码:（rest接口，供前台进行调用）</p>
<div class="cnblogs_code"><div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy"><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="./test_files/copycode.gif" alt="复制代码"></a></span></div>
<pre><span style="color: rgba(0, 128, 0, 1)">　　/**</span><span style="color: rgba(0, 128, 0, 1)">
     * 下载文件   
     *
     * </span><span style="color: rgba(128, 128, 128, 1)">@return</span>
     <span style="color: rgba(0, 128, 0, 1)">*/</span><span style="color: rgba(0, 0, 0, 1)">
    @RequestMapping(</span>"/downloadFile.do_"<span style="color: rgba(0, 0, 0, 1)">)
    @ResponseBody
    </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> downloadFile(
            HttpServletResponse response,
            @RequestParam String fileUrl,
            @RequestParam String fileName
    ) {
        downLoadFromUrl(fileUrl,fileName,response);
    }

    </span><span style="color: rgba(0, 128, 0, 1)">/**</span><span style="color: rgba(0, 128, 0, 1)">
     * 从网络Url中下载文件
     * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> urlStr       指定的url
     * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> fileName     下载文件完成要叫的名字
     * </span><span style="color: rgba(128, 128, 128, 1)">@param</span><span style="color: rgba(0, 128, 0, 1)"> response
     </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
    <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)">  downLoadFromUrl(String urlStr,String fileName,HttpServletResponse response){

        </span><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
            URL url </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> URL(urlStr);
            HttpURLConnection conn </span>=<span style="color: rgba(0, 0, 0, 1)"> (HttpURLConnection)url.openConnection();
　　　　
    　　　　　</span><span style="color: rgba(0, 128, 0, 1)">//增加头部，说明该文件为附件，只能进行下载，不直接读</span>
            response.setContentType("application/x-msdownload; charset=UTF-8"<span style="color: rgba(0, 0, 0, 1)">);
            response.setHeader(</span>"Content-Disposition", "attachment; filename=" +<span style="color: rgba(0, 0, 0, 1)"> fileName);

            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">得到输入流</span>
            InputStream inputStream =<span style="color: rgba(0, 0, 0, 1)"> conn.getInputStream();

            BufferedInputStream bis </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> BufferedInputStream(inputStream);
            OutputStream os </span>=<span style="color: rgba(0, 0, 0, 1)"> response.getOutputStream();
            BufferedOutputStream bos </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> BufferedOutputStream(os);
            </span><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)"> ContentLength必须设置，否则文件下载不全
             * 或者调用 BufferedOutputStream#write(byte[] b, int off, int len) 方法输出
             </span><span style="color: rgba(0, 128, 0, 1)">*/</span><span style="color: rgba(0, 0, 0, 1)">
            response.setContentLength(bis.available());
            </span><span style="color: rgba(0, 0, 255, 1)">byte</span>[] b = <span style="color: rgba(0, 0, 255, 1)">new</span> <span style="color: rgba(0, 0, 255, 1)">byte</span>[1024<span style="color: rgba(0, 0, 0, 1)">];
            </span><span style="color: rgba(0, 0, 255, 1)">while</span>(bis.read(b) != -1<span style="color: rgba(0, 0, 0, 1)">) {
                bos.write(b);
            }
            bos.flush();


            LOGGER.info(</span>"info:"+fileName+" download success"<span style="color: rgba(0, 0, 0, 1)">);
        } </span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
            LOGGER.error(</span>"uploadFile failed"<span style="color: rgba(0, 0, 0, 1)">, e);
        }

    }</span></pre>
<div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy"><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="./test_files/copycode.gif" alt="复制代码"></a></span></div></div>
<p><span style="font-size: 16px"><span style="color: rgba(255, 0, 0, 1)"><strong>注意</strong></span>：上面的方法有一个小问题：用过url去网络获取 inputStream 是一点一点不断获取，获取的过程中就去写这个 inputStream&nbsp;&nbsp;，则 inputStream&nbsp; 还没有获取完就写了，导致文件最后有缺失，所以可以给 inputStream 加一个同步锁synchronized，就能使 inputStream&nbsp; 全部获取完并写，这样就能获取完整的 inputStream 并写下来，就能下载一个完整的文件</span></p>
<div class="cnblogs_code"><div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy"><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="./test_files/copycode.gif" alt="复制代码"></a></span></div>
<pre><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)">  downLoadFromUrl(String urlStr,String fileName,HttpServletResponse response){

        URL url </span>= <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
        HttpURLConnection conn </span>= <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
        </span><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
            url </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> URL(urlStr);
            conn </span>=<span style="color: rgba(0, 0, 0, 1)"> (HttpURLConnection)url.openConnection();
        }</span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (Exception e) {
            LOGGER.error(</span>"HttpURLConnection failed"<span style="color: rgba(0, 0, 0, 1)">, e);
        }
        </span><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> (
                InputStream inputStream </span>=<span style="color: rgba(0, 0, 0, 1)"> conn.getInputStream();
                BufferedInputStream bis </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> BufferedInputStream(inputStream);
                OutputStream os </span>=<span style="color: rgba(0, 0, 0, 1)"> response.getOutputStream();
                BufferedOutputStream bos </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> BufferedOutputStream(os);
        ) {
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">未知上传的文件类型设置ContentType 和 Header</span>
            response.setContentType("application/octet-stream; charset=UTF-8"<span style="color: rgba(0, 0, 0, 1)">);
            response.setHeader(</span>"Content-Disposition", "attachment; filename=" + <span style="color: rgba(0, 0, 255, 1)">new</span> String(fileName.getBytes(),"ISO8859-1"<span style="color: rgba(0, 0, 0, 1)">));

            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">同步块，同步 inputStream ，边获取 inputStream 边写，一直到全部获取完 inputStream</span>
            <span style="color: rgba(0, 0, 255, 1)">synchronized</span><span style="color: rgba(0, 0, 0, 1)"> (inputStream) {
                </span><span style="color: rgba(0, 0, 255, 1)">byte</span>[] b = <span style="color: rgba(0, 0, 255, 1)">new</span> <span style="color: rgba(0, 0, 255, 1)">byte</span>[1024<span style="color: rgba(0, 0, 0, 1)">];
                </span><span style="color: rgba(0, 0, 255, 1)">int</span> count = 0<span style="color: rgba(0, 0, 0, 1)">;
                </span><span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)"> len;
                </span><span style="color: rgba(0, 0, 255, 1)">while</span>((len = bis.read(b)) != -1<span style="color: rgba(0, 0, 0, 1)">) {
                    bos.write(b, </span>0<span style="color: rgba(0, 0, 0, 1)">, len);
                    count</span>++<span style="color: rgba(0, 0, 0, 1)">;
                }
                bos.flush();
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">多少 Kb 大小的文件，则循环多少次，为count值</span>
                LOGGER.info("write BufferedOutputStream：" +<span style="color: rgba(0, 0, 0, 1)"> count);
                LOGGER.info(</span>"info:" + fileName + " download success"<span style="color: rgba(0, 0, 0, 1)">);
            }
        } </span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (Exception e) {
            LOGGER.error(</span>"uploadFile failed"<span style="color: rgba(0, 0, 0, 1)">, e);
        }

    }</span></pre>
<div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy"><a href="javascript:void(0);" onclick="copyCnblogsCode(this)" title="复制代码"><img src="./test_files/copycode.gif" alt="复制代码"></a></span></div></div>
<p>&nbsp;</p>
<p><strong><span style="font-size: 18pt">会出现如下通常我们网上点击某超链接下载文件的效果：（下载完成出现在浏览器页面左下角）</span></strong></p>
<p><img src="./test_files/1451134-20181109174301318-512443784.png" alt="" class="medium-zoom-image"></p>
</div>
<div class="clear"></div>
<div id="blog_post_info_block"><div id="BlogPostCategory">
    分类: 
            <a href="https://www.cnblogs.com/liuqing576598117/category/1390489.html" target="_blank">其他</a></div>


    <div id="blog_post_info">
<div id="green_channel">
        <a href="javascript:void(0);" id="green_channel_digg" onclick="DiggIt(9936400,cb_blogId,1);green_channel_success(this,&#39;谢谢推荐！&#39;);">好文要顶</a>
        <a id="green_channel_follow" onclick="follow(&#39;3891dd62-af14-49eb-38a3-08d5f07434ca&#39;);" href="javascript:void(0);">关注我</a>
    <a id="green_channel_favorite" onclick="AddToWz(cb_entryId);return false;" href="javascript:void(0);">收藏该文</a>
    <a id="green_channel_weibo" href="javascript:void(0);" title="分享至新浪微博" onclick="ShareToTsina()"><img src="./test_files/icon_weibo_24.png" alt=""></a>
    <a id="green_channel_wechat" href="javascript:void(0);" title="分享至微信" onclick="shareOnWechat()"><img src="./test_files/wechat.png" alt=""></a>
</div>
<div id="author_profile">
    <div id="author_profile_info" class="author_profile_info">
            <a href="https://home.cnblogs.com/u/liuqing576598117/" target="_blank"><img src="./test_files/sample_face.gif" class="author_avatar" alt=""></a>
        <div id="author_profile_detail" class="author_profile_info">
            <a href="https://home.cnblogs.com/u/liuqing576598117/">一中晴哥威武</a><br>
            <a href="https://home.cnblogs.com/u/liuqing576598117/followees/">关注 - 0</a><br>
            <a href="https://home.cnblogs.com/u/liuqing576598117/followers/">粉丝 - 7</a>
        </div>
    </div>
    <div class="clear"></div>
    <div id="author_profile_honor"></div>
    <div id="author_profile_follow">
                <a href="javascript:void(0);" onclick="follow(&#39;3891dd62-af14-49eb-38a3-08d5f07434ca&#39;);return false;">+加关注</a>
    </div>
</div>
<div id="div_digg">
    <div class="diggit" onclick="votePost(9936400,&#39;Digg&#39;)">
        <span class="diggnum" id="digg_count">0</span>
    </div>
    <div class="buryit" onclick="votePost(9936400,&#39;Bury&#39;)">
        <span class="burynum" id="bury_count">0</span>
    </div>
    <div class="clear"></div>
    <div class="diggword" id="digg_tips">
    </div>
</div>

<script type="text/javascript">
    currentDiggType = 0;
</script></div>
    <div class="clear"></div>
    <div id="post_next_prev">

    <a href="https://www.cnblogs.com/liuqing576598117/p/9936252.html" class="p_n_p_prefix">« </a> 上一篇：    <a href="https://www.cnblogs.com/liuqing576598117/p/9936252.html" title="发布于 2018-11-09 17:26">通过指定的 url 去网络或者文件服务器下载文件到本地某个文件夹</a>
    <br>
    <a href="https://www.cnblogs.com/liuqing576598117/p/9958350.html" class="p_n_p_prefix">» </a> 下一篇：    <a href="https://www.cnblogs.com/liuqing576598117/p/9958350.html" title="发布于 2018-11-14 15:50">synchronized锁住的是代码还是对象，以及synchronized底层实现原理</a>

</div>
</div>
        <div class="postDesc">posted on 
<span id="post-date">2018-11-09 17:45</span>&nbsp;
<a href="https://www.cnblogs.com/liuqing576598117/">一中晴哥威武</a>&nbsp;
阅读(<span id="post_view_count">2092</span>)&nbsp;
评论(<span id="post_comment_count">0</span>)&nbsp;
<a href="https://i.cnblogs.com/EditPosts.aspx?postid=9936400" rel="nofollow">编辑</a>&nbsp;
<a href="javascript:void(0)" onclick="AddToWz(9936400);return false;">收藏</a>&nbsp;
<a href="javascript:void(0)" onclick="reportManager.report({ currentUserId: &#39;&#39;, targetType: &#39;blogPost&#39;, targetId: &#39;9936400&#39;, targetLink: &#39;https://www.cnblogs.com/liuqing576598117/p/9936400.html&#39;, title: &#39;前后台交互实现点击超链接通过指定的 url 去网络或者文件服务器下载文件&#39; })">举报</a></div>
    </div>
</div>


<script>
    markdown_highlight()
    var allowComments = true, cb_blogId = 447335, cb_blogApp = 'liuqing576598117', cb_blogUserGuid = '3891dd62-af14-49eb-38a3-08d5f07434ca';
    var cb_entryId = 9936400, cb_entryCreatedDate = '2018-11-09 17:45', cb_postType = 1;
    updatePostStats(
        [cb_entryId],
        function(id, count) { $("#post_view_count").text(count) },
        function(id, count) { $("#post_comment_count").text(count) })
    zoomManager.apply("#cnblogs_post_body img:not(.code_img_closed):not(.code_img_opened)");
</script>
<a name="!comments"></a>
<div id="blog-comments-placeholder"></div>
<div id="comment_form" class="commentform">
    <a name="commentform"></a>
    <div id="divCommentShow"></div>
    <div id="comment_nav"><span id="span_refresh_tips"></span><a href="javascript:void(0);" onclick="return RefreshCommentList();" id="lnk_RefreshComments" runat="server" clientidmode="Static">刷新评论</a><a href="https://www.cnblogs.com/liuqing576598117/p/9936400.html#" onclick="return RefreshPage();">刷新页面</a><a href="https://www.cnblogs.com/liuqing576598117/p/9936400.html#top">返回顶部</a></div>
    <div id="comment_form_container" style="visibility: visible;"><div class="login_tips">
    登录后才能查看或发表评论，立即 <a rel="nofollow" href="javascript:void(0);" class="underline" onclick="return account.login(&#39;!comments&#39;);">登录</a> 或者
    <a href="https://www.cnblogs.com/">逛逛</a> 博客园首页
</div>
</div>
    <div class="ad_text_commentbox" id="ad_text_under_commentbox"></div>
    <div id="cnblogs_ch"><a href="https://c.gridsumdissector.com/r/?gid=gad_545_sf71nlea&amp;ck=1057&amp;adk=10670&amp;autorefresh=__AUTOREFRESH__" target="_blank" onclick="gtag(&#39;event&#39;, &#39;click&#39;, {&#39;event_category&#39;: &#39;ad&#39;, &#39;event_label&#39;: &#39;T2-火山引擎-1203-1209&#39;})">【推荐】字节跳动旗下火山引擎，邀您共同揭秘“云+增长”</a><br><a href="http://www.uccpsoft.com/index.htm" target="_blank" onclick="gtag(&#39;event&#39;, &#39;click&#39;, {&#39;event_category&#39;: &#39;ad&#39;, &#39;event_label&#39;: &#39;T2-ucancode&#39;})">【推荐】跨平台组态\工控\仿真\CAD 50万行C++源码全开放免费下载！</a><br><a href="https://brands.cnblogs.com/huawei/p/2704" target="_blank" onclick="gtag(&#39;event&#39;, &#39;click&#39;, {&#39;event_category&#39;: &#39;ad&#39;, &#39;event_label&#39;: &#39;T2-华为专区&#39;})">【推荐】华为 HarmonyOS 校园极客秀征文活动第1期，秀出你的COOL</a><br></div>
    <div id="opt_under_post"></div>
    <div id="cnblogs_c1" class="under-post-card" style="display: none;">
        <div id="div-gpt-ad-1592365906576-0" style="width: 300px; height: 250px;"></div>
    </div>
    <div id="under_post_card1"><div class="under-post-card">
<b>编辑推荐：</b>
<br>

· <a href="https://www.cnblogs.com/coco1s/p/15627657.html" target="_blank">使用 CSS 轻松实现一些高频出现的奇形怪状按钮</a>
    <br>
· <a href="https://www.cnblogs.com/strick/p/15394367.html" target="_blank">带团队后的日常思考（六）</a>
    <br>
· <a href="https://www.cnblogs.com/xiao2shiqi/p/15623540.html" target="_blank">聊聊云原生和微服务架构</a>
    <br>
· <a href="https://www.cnblogs.com/youzhibing/p/15615272.html" target="_blank">异或运算的巧用：不用额外的变量，如何交换两个变量的值？ </a>
    <br>
· <a href="https://www.cnblogs.com/myshowtime/p/15596630.html" target="_blank">OAuth 2.1 带来了哪些变化</a>
    <br>
</div></div>
        <div id="cnblogs_c2" class="under-post-card">
            <a href="https://c.gridsumdissector.com/r/?gid=gad_545_wrrk6jpf&amp;ck=1057&amp;adk=10673&amp;autorefresh=__AUTOREFRESH__" rel="nofollow" target="_blank">
                <img src="./test_files/volcengine-c2.jpg" alt="" onload="impressC2(&#39;火山引擎&#39;, &#39;https://i.gridsumdissector.com/v/?gscmd=impress&amp;gid=gad_545_wrrk6jpf&amp;ck=1057&amp;adk=10673&amp;autorefresh=__AUTOREFRESH__&amp;ts=__TS__&#39;)">
            </a>
        </div>
    <div id="under_post_card2"><div class="itnews under-post-card">
    <b>最新新闻</b>：
    <br>
 ·          <a href="https://news.cnblogs.com/n/708312/" target="_blank">豆瓣是中国互联网的骄傲（2021-12-03 14:30）</a>
        <br>
 ·          <a href="https://news.cnblogs.com/n/708311/" target="_blank">虚幻引擎5何时发布、中小团队能用吗？一切答案都在Unreal Open Day 2021（2021-12-03 14:23）</a>
        <br>
 ·          <a href="https://news.cnblogs.com/n/708310/" target="_blank">李想的理想：好产品不需要刷存在感（2021-12-03 14:18）</a>
        <br>
 ·          <a href="https://news.cnblogs.com/n/708309/" target="_blank">柳夜熙一夜暴粉，顶级品牌悉数入局，元宇宙的热点不好蹭（2021-12-03 14:10）</a>
        <br>
 ·          <a href="https://news.cnblogs.com/n/708308/" target="_blank">特斯拉儿童版越野车亮相官网！仅售1900美元，8岁就能开，支持自己组装（2021-12-03 13:58）</a>
        <br>
    » <a href="https://news.cnblogs.com/" title="IT 新闻" target="_blank">更多新闻...</a>
</div></div>
    <div id="HistoryToday" class="under-post-card"></div>
    <script type="text/javascript">
       var commentManager = new blogCommentManager();
       commentManager.renderComments(0);
       fixPostBody();

           window.tocManager.displayDisableTocTips = false
           window.tocManager.generateToc();
           setTimeout(function() { incrementViewCount(cb_entryId); }, 50);       deliverT2();
       deliverC1C2();
       loadNewsAndKb();
LoadPostCategoriesTags(cb_blogId, cb_entryId);       LoadPostInfoBlock(cb_blogId, cb_entryId, cb_blogApp, cb_blogUserGuid);
       GetPrevNextPost(cb_entryId, cb_blogId, cb_entryCreatedDate, cb_postType);
       loadOptUnderPost();
       GetHistoryToday(cb_blogId, cb_blogApp, cb_entryCreatedDate);
    </script>
</div>



	<!--done-->
<div class="footer">
	Copyright © 2021 一中晴哥威武
<br><span id="poweredby">Powered by .NET 6 on Kubernetes</span>
 Powered by: <a href="http://www.cnblogs.com/" class="footerlink">博客园</a><br>
</div>


</div>




    

    <input type="hidden" id="antiforgery_token" value="CfDJ8FO3GXnjClZGrNGr2Ic8Z1q69-IDHHgqbo5ImUm7OLC0Sn4rGdb8hYujSxrONN9O9W59RkR-aebSpciLuVf5IH-rvmZv4X7UZvAL-gjAdWcbc9np94pGVTRcNrUmeR2iFkbd5JoWpqpW35AFRLcwXVw">
    <script async="" src="./test_files/js"></script>
    <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    var kv = getGACustom();
    if (kv) {
        gtag('set', kv);
    }
    gtag('config', 'UA-476124-1');
    </script>
    <script defer="" src="./test_files/hm.js.下载"></script>

</body></html>